package demo.server.log;

import java.io.File;

import org.apache.log4j.xml.DOMConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import demo.server.common.ServerConstant;
import demo.server.model.QueueModel;

public class WriteLog extends Thread{
	
	private QueueModel que;
	private Logger log = null;
	
	public WriteLog(QueueModel que){
		this.que = que;
	}
	
	public void loadConfig(){
		String path = ServerConstant.logParth + "socketLib" + File.separator;
		DOMConfigurator.configureAndWatch(path + "serverConfig.log4j.xml");
		log = LoggerFactory.getLogger("LogValue");
	}
	
	private void writingLog(){
		while(true){
			if (que.size() > 0) {
				String value = que.removeFirst();
				log.info(value);
			} else{
				synchronized (que) {
					try {
						que.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
	
	@Override
	public void run() {
		loadConfig();
		writingLog();
	}
}
